package tony.test.crypto.digest

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertNotNull
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import tony.crypto.digest.sm3

@Nested
@DisplayName("CharSequence.sm3()测试")
class Sm3Test {
    @ParameterizedTest
    @ValueSource(strings = ["hello", "world", "test", "Tony测试123!@#"])
    @DisplayName("CharSequence.sm3():正常字符串")
    fun testSm3WithNormalString(value: String) {
        val sm3Result = value.sm3()

        assertNotNull(sm3Result)
        Assertions.assertEquals(64, sm3Result.length)
        Assertions.assertTrue(sm3Result.all { it.isLetterOrDigit() })
    }

    @Test
    @DisplayName("CharSequence.sm3():相同字符串")
    fun testSm3WithSameString() {
        val testString = "Tony测试123!@#"
        val sm3Result1 = testString.sm3()
        val sm3Result2 = testString.sm3()
        Assertions.assertEquals(sm3Result1, sm3Result2)
    }

    @Test
    @DisplayName("CharSequence.sm3():空字符串")
    fun testSm3WithEmptyString() {
        val emptySm3 = "".sm3()
        assertNotNull(emptySm3)
        Assertions.assertEquals(64, emptySm3.length)
    }

    @Test
    @DisplayName("CharSequence.sm3():StringBuilder")
    fun testSm3WithStringBuilder() {
        val stringBuilder = StringBuilder("Tony测试123!@#")
        val sm3Result = stringBuilder.sm3()

        assertNotNull(sm3Result)
        Assertions.assertEquals(64, sm3Result.length)
    }

    @Test
    @DisplayName("CharSequence.sm3():StringBuffer")
    fun testSm3WithStringBuffer() {
        val stringBuffer = StringBuffer("Tony测试123!@#")
        val sm3Result = stringBuffer.sm3()

        assertNotNull(sm3Result)
        Assertions.assertEquals(64, sm3Result.length)
    }
}
